<template>
	<view style="width: 100%;">
		<view class="details">
			<view class="details__kong" v-if="!news_list.length">
				<image class="details__kong__img" src="/static/icon/kong_icon_bg.png" mode=""></image>
				暂无新闻
			</view>
			<view v-if="news_list.length" class="details__box" @click="goDetail(detail,d_index)" v-for="(detail, d_index) in news_list" :key='d_index'>
				<view class="details__box__less" v-if="detail.newsImg.split(',').length <= 2">
					<view class="details__box__less__content">
						<view class="details__box__less__content__text"><text class="details__box__less__content__text__title" :style="detail.newsStatus == 0?'color: #333333;':'color: rgb(154,154,154);'">{{detail.newsTitle}}</text></view>
						<!-- <view class="details__box__less__content__info"><text class="details__box__less__content__info__text">{{detail.newsInfo}}</text></view> -->
						<view class="details__box__less__content__source">
							<text>{{detail.newsSource}}</text>
						</view>
						<view class="details__box__less__content__time">
							<text>{{detail.createTime}}</text>
						</view>
					</view>
					<view v-if="img_index < 1" v-for="(img,img_index) in detail.newsImg.split(',')" :key="img_index" style="width: 213rpx;height: 213rpx;border-radius: 14rpx;">
						<image :src="img" style="width: 100%;height: 100%;border-radius: 14rpx;" mode="aspectFill"></image>
					</view>
				</view>
				<!-- 多图 -->
				<view class="details__box__many" v-if="detail.newsImg.split(',').length > 2">
					<view class="details__box__many__box">
						<view class="details__box__many__box__title"><text class="details__box__many__box__title__text"  :style="detail.newsStatus == 0?'color: #333333;':'color: rgb(154,154,154);'">{{detail.newsTitle}}</text></view>
						<!-- <view class="details__box__many__box__info"><text>{{detail.newsInfo}}</text></view> -->
						<view class="details__box__many__box__content">
							<view class="details__box__many__box__content__item" v-if="img_index < 3" v-for="(img,img_index) in detail.newsImg.split(',')" :key="img_index">
								<image class="details__box__many__box__content__item__img" :src="img" mode="aspectFill"></image>
							</view>
						</view>
						<view>
							<text class="details__box__many__box__source">{{detail.newsSource}}</text>
							<text class="details__box__many__box__time">{{detail.createTime}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import moment from 'utils/moment.min.js'
	
	export default {
		data() {
			return {
				news_list: [], //新闻列表
				pageNo: 1, //页面数
			}
		},
		onLoad() {
			let self = this
			self.getNew()
		},
		methods: {
			/**
			 * @name 获取新闻
			 */
			getNew() {
				let self = this
				//新闻
				self.$api.fAppNewsList({
					pageNo: self.pageNo,
					pageSize: 10,
				}).then((res) => {
					// console.log(res.data.result.records);
					self.news_list = res.data.result.records
					self.news_list.forEach((item, index) => {
						item.createTime = moment(item.createTime).format('YYYY.MM.DD');
					})
				})
			},
			/**
			 * @name 详情跳转
			 * @param {Object} detail 内容
			 * @param {Object} index 索引值
			 */
			goDetail(detail,index) {
				uni.navigateTo({
					url:'/pages/index/newsList/newDetail/newDetail?type=1&item=' + encodeURIComponent(JSON.stringify(detail)) + '&index=' + index
				})
			},
		},
		onReachBottom() {
			let self = this
			self.pageNo ++
			//新闻
			self.$api.fAppNewsList({
				pageNo: self.pageNo,
				pageSize: 10,
			}).then((res) => {
				if(res.data.result.records.length == 0) {
					self.pageNo --
				}else{
					res.data.result.records.forEach((item, index) => {
						item.createTime = moment(item.createTime).format('YYYY.MM.DD');
					})
					self.news_list = self.news_list.concat(res.data.result.records)
				}
			})
		},
	}
</script>

<style scoped lang="less">
	.details {
		width: 100%;
		margin-top: 10rpx;
		border-top: 2rpx solid rgba(248,248,248,1);
		&__kong {
			width: 100%;display: flex;align-items: center;flex-direction: column;position: fixed;top: 26%;
			&__img {
				width: 422rpx;height: 298rpx;
			}
		}
		&__box {
			width: 93.7%;
			padding: 12rpx 22rpx;
			display: flex;
			align-items: center;
			justify-content: space-evenly;
			border-radius: 14rpx;
			margin-bottom: 6rpx;
			box-shadow: 0px 5px 20px 0px rgba(143, 143, 143, 0.1);
			&__less {
				width: 100%;height: 287rpx;padding: 12rpx 22rpx;display: flex;align-items: center;justify-content: space-evenly;border-radius: 14rpx;
				&__content {
					width: 64%;height: 233rpx;display: flex;flex-direction: column;justify-content: space-between;
					&__text {
						height: 76rpx;
						&__title {
							font-size: 30rpx;color: #333333;display: -webkit-box;-webkit-box-orient: vertical;word-break: break-all;-webkit-line-clamp: 3;overflow: hidden;text-overflow: ellipsis;
						}
					}
					&__info {
						height: 64rpx;
						&__text {
							font-size: 24rpx;color: rgba(102,102,102,1);display: -webkit-box;-webkit-box-orient: vertical;word-break: break-all;-webkit-line-clamp: 3;overflow: hidden;text-overflow: ellipsis;
						}
					}
					&__source {
						font-size: 24rpx;color: rgba(49,114,182,1);margin-top: 58rpx;
					}
					&__time {
						font-size: 24rpx;color: rgba(153,153,153,1);
					}
				}
			}
			&__many {
				width: 100%;height: 520rpx;padding: 12rpx 22rpx;display: flex;align-items: center;border-radius: 14rpx;
				&__box {
					width: 100%;height: 466rpx;display: flex;flex-direction: column;justify-content: space-between;
					&__title {
						height: 76rpx;
						&__text {
							font-size: 30rpx;color: #333333;display: -webkit-box;-webkit-box-orient: vertical;word-break: break-all;-webkit-line-clamp: 3;overflow: hidden;text-overflow: ellipsis;
						}
					}
					&__info {
						width: 100%;height: 64rpx;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;font-size: 24rpx;color: rgba(102,102,102,1);
					}
					&__content {
						width: 100%;height: 233rpx;display: flex;align-items: center;justify-content: space-between;
						&__item {
							width: 32%;height: 233rpx;border-radius: 14rpx;display: flex;align-items: center;justify-content: space-between;
							&__img {
								width: 100%;height: 100%;border-radius: 14rpx;
							}
						}
					}
					&__source {
						font-size: 24rpx;color: rgba(49,114,182,1);
					}
					&__time {
						font-size: 24rpx;color: rgba(153,153,153,1);margin-left: 32rpx;
					}
				}
			}
		}
	}
</style>
